﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
namespace Constructor.Controls.DynamicPart
{
    public partial class ProcedurePart : UserControl
    {
        public Procedure Procedure { get; set; }
        public ProcedurePart()
        {
            InitializeComponent();
        }
        public void Init(Procedure p)
        {
            Procedure = p;
            if (Procedure.Production.Item.Content.Domain.Type == CommonLib.DomainType.Number)
            {
                cmb_method.Items.Clear();
                cmb_method.Items.AddRange(FunctionControler.ListMethods(typeof(int)).ToArray());
                if (cmb_method.Items.Count > 0 && Procedure.Method == null)
                    cmb_method.SelectedIndex = 0;
                else
                    cmb_method.SelectedItem = Procedure.Method.Name;
            }
        }

        private void cmb_method_SelectedIndexChanged(object sender, EventArgs e)
        {
            flowLayoutPanel1.Controls.Clear();
            if (cmb_method.SelectedItem != null)
            {
                Procedure.Method = FunctionControler.GetMethod(cmb_method.Text);
                if (Procedure.Method != null)
                    foreach (ParameterInfo p in Procedure.Method.GetParameters())
                        flowLayoutPanel1.Controls.Add(new FuncParam(p, Procedure));
            }
        }
    }
}
